import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import './assets/main.css'

// 配置 axios
axios.defaults.baseURL = 'http://localhost:8000'
axios.defaults.withCredentials = true
axios.defaults.timeout = 5000

// 添加响应拦截器
axios.interceptors.response.use(
  response => response,
  error => {
    if (error.response) {
      // 处理错误响应
      console.error('Response error:', error.response.data)
    } else if (error.request) {
      // 请求发出但没有收到响应
      console.error('Request error:', error.request)
    } else {
      // 请求设置时发生错误
      console.error('Error:', error.message)
    }
    return Promise.reject(error)
  }
)

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ElementPlus, {
  locale: zhCn,
})

app.mount('#app')
